package com.ciwong.epaper.ui;

import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.AlphaAnimation;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.application.EApplication;
import com.ciwong.epaper.bean.BrandBean;
import com.ciwong.epaper.bean.RegistUser;
import com.ciwong.epaper.bean.UserAccountInfo;
import com.ciwong.epaper.modules.login.BrandAccountAdapter;
import com.ciwong.epaper.modules.login.LoginAccountAdapter;
import com.ciwong.epaper.modules.login.LoginContract;
import com.ciwong.epaper.modules.login.LoginPresenterImpl;
import com.ciwong.epaper.modules.login.PopListItemListener;
import com.ciwong.epaper.modules.me.ui.AgreementActivity;
import com.ciwong.epaper.modules.me.util.MeJumpManager;
import com.ciwong.epaper.modules.me.util.MeUtil;
import com.ciwong.epaper.modules.pad.contentprovider.LoginToken;
import com.ciwong.epaper.modules.pad.contentprovider.MyGradeWidgetProvider;
import com.ciwong.epaper.modules.pad.homeworkwidget.widget.HomeworkWidgetProvider;
import com.ciwong.epaper.util.AESCBCUtil;
import com.ciwong.epaper.util.DeviceUtil;
import com.ciwong.epaper.util.EConstants;
import com.ciwong.epaper.util.EJumpManager;
import com.ciwong.epaper.util.IntentFlag;
import com.ciwong.epaper.util.RequestCode;
import com.ciwong.epaper.util.SerializableManager;
import com.ciwong.libs.utils.CWSys;
import com.ciwong.mobilelib.i.BaseCallBack;
import com.ciwong.mobilelib.i.ViewOnClickListener;
import com.ciwong.mobilelib.ui.BaseActivity;
import com.ciwong.mobilelib.utils.BaseIntentFlag;
import com.ciwong.mobilelib.utils.ImageLoaderHelper;
import com.ciwong.mobilelib.utils.ToastUtil;
import com.ciwong.mobilelib.widget.CWDialog;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;

/**
 * 登录页面
 * Created by lqi on 2017/2/20.
 */
public class NewLoginActivity extends BaseActivity implements LoginContract.LoginView {

    private static final int REQUEST_CODE_REGISTER_ACCOUNT = 0x0000031;
    public static int FOR_LOGIN = 1;

    private LinearLayout ll_login_input, youke_login_bt, login_input_lay, real_name_login_input_lay;

    private LinearLayout choose_school_login_input, chinese_name_layout, input_password_layout;

    private LinearLayout ll_logo_captcha_code, ll_login_name_captcha_code;

    private RelativeLayout quick_login_layout, real_name_login_layout;

    private TextView choose_school_edit, quick_login_text, real_name_login_text, real_login_forgit_passwrd;

    private EditText edt_chinese_nam, edt_password, edt_login_captcha_code, edt_login_name_captcha_code;

    private View quick_login_view, real_name_login_view;


    private ViewGroup container;

    private EditText loginAccount, edt_loginPassword;

    private ImageView loginMore, iv_captcha_code, iv_name_captcha_code;

    private PopupWindow loginAccountPop;

    private Button loginLogin;

    private CheckBox check_agreement;

    private CheckBox check_pwd_show_close;

    private TextView loginRegister, forgit_passwrd;

    private LoginContract.LoginPresenter mLoginPresenter;

    private LoginAccountAdapter mAccountAdapter;

    private TextView phone_number_text;

    /**
     * 学校id
     */
    private long schoolId;
    /**
     * 学校名
     */
    private String schoolName;

    //是否是快捷登录
    private boolean isQuickLogin = true;
    private String packageName = "";
    private View mBelowLoginLL;
    private RelativeLayout mRegisterRl;
    private ImageView mIvPwdDel, mIvAccountDel, mIvLogo, mIvCaptchaDel;
    private String uuid = UUID.randomUUID().toString();
    private static final String TAG = "NewLoginActivity";
    private ViewOnClickListener mViewOnClickListener = new ViewOnClickListener() {
        @Override
        public void avertRepeatOnClick(View v) {
            int id = v.getId();
            if (id == R.id.login_more) {
                Log.i("lqi", "-----------showAccountPop---");
                showAccountPop();
            } else if (id == R.id.youke_login_bt) {
                EConstants.IS_YOUKE = true;
                login();
            } else if (id == R.id.loginLogin) {
                EConstants.IS_YOUKE = false;
                if (!check_agreement.isChecked()) {
                    ToastUtil.INSTANCE.toastCenterError(R.string.login_tips);
                } else {
                    login();
                }

            } else if (id == R.id.login_register) {
                //跳转到验证手机号
                MeJumpManager.jumpToBindPhoneActivity(R.string.go_back, NewLoginActivity.this, "", "3");
            } else if (id == R.id.forgit_passwrd) {
                //跳转到验证手机号页面
                String phoneNumber = "";
                MeJumpManager.jumpToBindPhoneActivity(R.string.go_back, NewLoginActivity.this, phoneNumber, "1");
            } else if (id == R.id.real_login_forgit_passwrd) {
                //跳转到验证手机号页面
                String phoneNumber = "";
                MeJumpManager.jumpToBindPhoneActivity(R.string.go_back, NewLoginActivity.this, phoneNumber, "1");
            } else if (id == R.id.account_del_text) {
                loginAccount.setText("");
                mIvAccountDel.setVisibility(View.GONE);
            } else if (id == R.id.pwd_del_text) {
                edt_loginPassword.setText("");
                mIvPwdDel.setVisibility(View.GONE);
            } else if (id == R.id.captcha_del_text) {
                edt_login_captcha_code.setText("");
                mIvCaptchaDel.setVisibility(View.GONE);
            } else if (id == R.id.tv_agreement) {
                //使用协议
                MeJumpManager.jumpAgreementActivity(R.string.go_back, NewLoginActivity.this, getString(R.string.agreement_use_url), getString(R.string.agreement_private), AgreementActivity.LOGIN_ACTION);
            } else if (id == R.id.tv_agreement_secret) {
                //隐私协议
                MeJumpManager.jumpAgreementActivity(R.string.go_back, NewLoginActivity.this, getString(R.string.agreement_secret_url), getString(R.string.agreement_secret), AgreementActivity.LOGIN_ACTION);
            } else if (id == R.id.tv_agreement_child) {
                //儿童隐私保护政策
                MeJumpManager.jumpAgreementActivity(R.string.go_back, NewLoginActivity.this, getString(R.string.agreement_child_url), getString(R.string.agreement_child), AgreementActivity.LOGIN_ACTION);
            } else if (id == R.id.real_name_login_layout) {
                isQuickLogin = false;
                if (TextUtils.isEmpty(edt_password.getText().toString()) || TextUtils.isEmpty(edt_chinese_nam.getText().toString()) ||
                        TextUtils.isEmpty(choose_school_edit.getText().toString())) {
                    loginLogin.setEnabled(false);
                } else {
                    loginLogin.setEnabled(true);
                }
                setQuickLoginOrRealNameLogin(false);
            } else if (id == R.id.quick_login_layout) {
                isQuickLogin = true;
                if (TextUtils.isEmpty(edt_loginPassword.getText().toString()) || TextUtils.isEmpty(loginAccount.getText().toString())) {
                    loginLogin.setEnabled(false);
                } else {
                    loginLogin.setEnabled(true);
                }
                setQuickLoginOrRealNameLogin(true);
            } else if (id == R.id.choose_school_login_input || id == R.id.choose_school_edit) {
                MeJumpManager.jumpToChooseCitySchoolActivity(R.string.go_back, NewLoginActivity.this, RequestCode.MainActivityResquestCode.REQUEST_CODE_TO_CHOOSE_SCHOOL);
            } else if (id == R.id.phone_number_text) {
                //拨打客服电话
                MeJumpManager.jumpToCallPhone(0, NewLoginActivity.this, getString(R.string.service_phone));
            } else if (id == R.id.iv_captcha_code) {
                //刷新验证码（需要验证码的时候在打开）
//                setCaptchaCode(iv_captcha_code);
            } else if (id == R.id.iv_name_captcha_code) {
                //刷新验证码（需要验证码的时候在打开）
//                setCaptchaCode(iv_name_captcha_code);
            }
        }
    };

    /**
     * 设置不同登录方式ui显示
     *
     * @param isQuickLogin 是否是快捷登录
     */
    public void setQuickLoginOrRealNameLogin(boolean isQuickLogin) {
        if (isQuickLogin) {
            real_name_login_text.setTextColor(getResources().getColor(R.color.ls_text_color));
            quick_login_text.setTextColor(getResources().getColor(R.color.color_light_green));
            real_name_login_view.setVisibility(View.INVISIBLE);
            quick_login_view.setVisibility(View.VISIBLE);
            real_name_login_view.setBackgroundColor(getResources().getColor(R.color.ls_text_color));
            quick_login_view.setBackgroundColor(getResources().getColor(R.color.color_light_green));
            login_input_lay.setVisibility(View.VISIBLE);
            real_name_login_input_lay.setVisibility(View.GONE);
//            setCaptchaCode(iv_captcha_code);//（需要验证码的时候在打开）
        } else {
            real_name_login_text.setTextColor(getResources().getColor(R.color.color_light_green));
            quick_login_text.setTextColor(getResources().getColor(R.color.ls_text_color));
            real_name_login_view.setVisibility(View.VISIBLE);
            quick_login_view.setVisibility(View.INVISIBLE);
            real_name_login_view.setBackgroundColor(getResources().getColor(R.color.color_light_green));
            quick_login_view.setBackgroundColor(getResources().getColor(R.color.ls_text_color));
            login_input_lay.setVisibility(View.GONE);
            real_name_login_input_lay.setVisibility(View.VISIBLE);
//            setCaptchaCode(iv_name_captcha_code);//（需要验证码的时候在打开）
        }
    }

    @Override
    protected void preCreate() {
        super.preCreate();
    }

    @Override
    protected int setView() {
        return R.layout.activity_login_layout;
    }


    @Override
    protected void findViews() {
        container = findViewById(R.id.container);
        ll_login_input = findViewById(R.id.ll_login_input);
        youke_login_bt = findViewById(R.id.youke_login_bt);
        loginAccount = findViewById(R.id.loginAccount);
        edt_loginPassword = findViewById(R.id.edt_loginPassword);
        ll_logo_password = findViewById(R.id.ll_logo_password);
        loginMore = findViewById(R.id.login_more);
        loginLogin = findViewById(R.id.loginLogin);
        loginRegister = findViewById(R.id.login_register);
        forgit_passwrd = findViewById(R.id.forgit_passwrd);

        tv_service_num = findViewById(R.id.tv_service_num);
        tv_agreement = findViewById(R.id.tv_agreement);
        tv_agreement_secret = findViewById(R.id.tv_agreement_secret);
        tv_agreement_child = findViewById(R.id.tv_agreement_child);
        ll_select_brand = findViewById(R.id.ll_select_brand);
        quick_login_layout = findViewById(R.id.quick_login_layout);
        real_name_login_layout = findViewById(R.id.real_name_login_layout);
        login_input_lay = findViewById(R.id.login_input_lay);
        real_name_login_input_lay = findViewById(R.id.real_name_login_input_lay);
        choose_school_login_input = findViewById(R.id.choose_school_login_input);
        input_password_layout = findViewById(R.id.input_password_layout);
        choose_school_edit = findViewById(R.id.choose_school_edit);
        edt_chinese_nam = findViewById(R.id.edt_chinese_nam);
        edt_password = findViewById(R.id.edt_password);
        quick_login_text = findViewById(R.id.quick_login_text);
        real_name_login_text = findViewById(R.id.real_name_login_text);
        quick_login_view = findViewById(R.id.quick_login_view);
        real_name_login_view = findViewById(R.id.real_name_login_view);
        real_login_forgit_passwrd = findViewById(R.id.real_login_forgit_passwrd);
        check_agreement = findViewById(R.id.check_agreement);
        check_pwd_show_close = findViewById(R.id.check_pwd_show_close);
        phone_number_text = findViewById(R.id.phone_number_text);
        ll_logo_captcha_code = findViewById(R.id.ll_logo_captcha_code);
        edt_login_captcha_code = findViewById(R.id.edt_login_captcha_code);
        iv_captcha_code = findViewById(R.id.iv_captcha_code);
        ll_login_name_captcha_code = findViewById(R.id.ll_login_name_captcha_code);
        edt_login_name_captcha_code = findViewById(R.id.edt_login_name_captcha_code);
        iv_name_captcha_code = findViewById(R.id.iv_name_captcha_code);
        if ("100151".equals(EConstants.CLIENT_ID)) {
            et_select_brand = findViewById(R.id.et_select_brand);
            iv_select_other_brand = findViewById(R.id.iv_select_other_brand);
            iv_select_other_brand.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showBrandAccountPop();
                }
            });
            ll_select_brand.setVisibility(View.VISIBLE);
            initNoPwdLogintPop(getBrandList());
        }
        mBelowLoginLL = findViewById(R.id.line_below_ll_login_input);
        mRegisterRl = findViewById(R.id.login_rl);
        mIvPwdDel = findViewById(R.id.pwd_del_text);
        mIvCaptchaDel = findViewById(R.id.captcha_del_text);
        mIvAccountDel = findViewById(R.id.account_del_text);
        mIvLogo = findViewById(R.id.iv_logo);
    }

    /**
     * 客服电话
     */
    private TextView tv_service_num;
    private TextView tv_agreement;
    private TextView tv_agreement_secret;
    private TextView tv_agreement_child;
    private boolean loginAccountChanged = false;
    private boolean pwdChanged = false;

    @Override
    protected void initEvent() {
        try {

            container.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    hideSoftInput(v);
                    return false;
                }
            });
            loginAccount.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                                              int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before,
                                          int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if ("100151".equals(EConstants.CLIENT_ID)) {

                    } else {
                        accountChange(s);
                    }
                    if (s.toString().length() > 0) {
                        mIvAccountDel.setVisibility(View.VISIBLE);
                        mIvPwdDel.setVisibility(View.GONE);
                        mIvCaptchaDel.setVisibility(View.GONE);
                    } else {
                        mIvAccountDel.setVisibility(View.GONE);
                    }

                }
            });
            edt_loginPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId,
                                              KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_DONE) {
                        EConstants.IS_YOUKE = false;
                        login();
                    }
                    return false;
                }
            });


            edt_loginPassword.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    String passWord = editable.toString();
                    if (TextUtils.isEmpty(passWord) || TextUtils.isEmpty(loginAccount.getText().toString())) {
                        loginLogin.setEnabled(false);
                    } else {
                        loginLogin.setEnabled(true);
                    }

                    if (passWord.toString().length() > 0) {
                        mIvPwdDel.setVisibility(View.VISIBLE);
                    } else {
                        mIvPwdDel.setVisibility(View.GONE);
                    }

                }
            });
            edt_login_captcha_code.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    String passWord = editable.toString();
                    if (TextUtils.isEmpty(passWord) || TextUtils.isEmpty(loginAccount.getText().toString()) ||
                            TextUtils.isEmpty(edt_loginPassword.getText().toString())) {
                        loginLogin.setEnabled(false);
                    } else {
                        loginLogin.setEnabled(true);
                    }

                    if (passWord.toString().length() > 0) {
                        mIvCaptchaDel.setVisibility(View.VISIBLE);
                        mIvPwdDel.setVisibility(View.GONE);
                        mIvAccountDel.setVisibility(View.GONE);
                    } else {
                        mIvCaptchaDel.setVisibility(View.GONE);
                    }
                }
            });

            edt_chinese_nam.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    String passWord = editable.toString();
                    if (TextUtils.isEmpty(passWord) || TextUtils.isEmpty(edt_password.getText().toString()) ||
                            TextUtils.isEmpty(choose_school_edit.getText().toString())) {
                        loginLogin.setEnabled(false);
                    } else {
                        loginLogin.setEnabled(true);
                    }

                }
            });

            edt_password.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    String passWord = editable.toString();
                    if (TextUtils.isEmpty(passWord) || TextUtils.isEmpty(edt_chinese_nam.getText().toString()) ||
                            TextUtils.isEmpty(choose_school_edit.getText().toString())) {
                        loginLogin.setEnabled(false);
                    } else {
                        loginLogin.setEnabled(true);
                    }

                }
            });
            edt_login_name_captcha_code.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    String passWord = editable.toString();
                    if (TextUtils.isEmpty(passWord) || TextUtils.isEmpty(edt_chinese_nam.getText().toString()) ||
                            TextUtils.isEmpty(choose_school_edit.getText().toString())) {
                        loginLogin.setEnabled(false);
                    } else {
                        loginLogin.setEnabled(true);
                    }

                }
            });
            loginMore.setOnClickListener(mViewOnClickListener);
            loginLogin.setOnClickListener(mViewOnClickListener);
            youke_login_bt.setOnClickListener(mViewOnClickListener);
            real_name_login_layout.setOnClickListener(mViewOnClickListener);
            quick_login_layout.setOnClickListener(mViewOnClickListener);
            choose_school_login_input.setOnClickListener(mViewOnClickListener);
            real_login_forgit_passwrd.setOnClickListener(mViewOnClickListener);
            choose_school_edit.setOnClickListener(mViewOnClickListener);
            phone_number_text.setOnClickListener(mViewOnClickListener);
            iv_captcha_code.setOnClickListener(mViewOnClickListener);
            iv_name_captcha_code.setOnClickListener(mViewOnClickListener);
            packageName = getPackageName();
            if (packageName.equals("com.ciwong.newspaper") ||
                    packageName.equals("com.ciwong.listenspeak") ||
                    packageName.equals("com.ciwong.aixiti") ||
                    packageName.equals("com.ciwong.handenglish") ||
                    packageName.equals("com.ciwong.demoenglish")) {
                mRegisterRl.setVisibility(View.GONE);
            } else {
                mRegisterRl.setVisibility(View.VISIBLE);
                loginRegister.setOnClickListener(mViewOnClickListener);
            }
            forgit_passwrd.setOnClickListener(mViewOnClickListener);
            tv_agreement.setOnClickListener(mViewOnClickListener);
            tv_agreement_secret.setOnClickListener(mViewOnClickListener);
            tv_agreement_child.setOnClickListener(mViewOnClickListener);
        } catch (NullPointerException e) {
            e.getStackTrace();
        }

        edt_loginPassword.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus && edt_loginPassword.getText().length() > 0) {
                    mIvPwdDel.setVisibility(View.VISIBLE);
                    mIvAccountDel.setVisibility(View.GONE);
                } else {
                    mIvPwdDel.setVisibility(View.GONE);
                }
            }
        });
        loginAccount.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus && loginAccount.getText().length() > 0) {
                    mIvAccountDel.setVisibility(View.VISIBLE);
                    mIvPwdDel.setVisibility(View.GONE);
                } else {
                    mIvAccountDel.setVisibility(View.GONE);
                }
            }
        });

        mIvPwdDel.setOnClickListener(mViewOnClickListener);
        mIvAccountDel.setOnClickListener(mViewOnClickListener);
        mIvCaptchaDel.setOnClickListener(mViewOnClickListener);
        //是否同意隐私协议
        boolean privacyAgreement = false;
        try {
            privacyAgreement = CWSys.getSharedBoolean("privacyAgreement" + packageName + getPackageManager()
                    .getPackageInfo(getPackageName(), 0).versionName, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (privacyAgreement) {
            check_agreement.setChecked(true);
        }
        check_agreement.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                try {
                    if (isChecked) {
                        CWSys.setSharedBoolean("privacyAgreement" + packageName + getPackageManager()
                                .getPackageInfo(getPackageName(), 0).versionName, true);
                        PackageManager packageManager = getPackageManager();
                        packageManager.setComponentEnabledSetting(new ComponentName(NewLoginActivity.this, MyGradeWidgetProvider.class),
                                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                                PackageManager.DONT_KILL_APP);
                        packageManager.setComponentEnabledSetting(new ComponentName(NewLoginActivity.this, HomeworkWidgetProvider.class),
                                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                                PackageManager.DONT_KILL_APP);
                    } else {
                        CWSys.setSharedBoolean("privacyAgreement" + packageName + getPackageManager()
                                .getPackageInfo(getPackageName(), 0).versionName, false);
                    }
                } catch (PackageManager.NameNotFoundException e) {
                    e.printStackTrace();
                }
            }
        });
        check_pwd_show_close.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                if (isChecked) {
                    // 设置为明文模式
                    edt_loginPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                } else {
                    // 设置为密码模式
                    edt_loginPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
                // 移动光标到末尾
                edt_loginPassword.setSelection(edt_loginPassword.getText().length());
            }
        });
    }

    @Override
    protected void init() {
        hideTitleBar();
        registStatistics(false);
        setValideSource(false);
        controlKeyboardLayout(container, loginLogin);
        mLoginPresenter = new LoginPresenterImpl((EApplication) getApplication(), this);
        if (DeviceUtil.isRoot()) {
            showConfirmDialog(NewLoginActivity.this);
        }
        SpannableStringBuilder agreementBuilder = new SpannableStringBuilder(getResources().getText(R.string.tv_agreement));
        ForegroundColorSpan agreementSpan = new ForegroundColorSpan(Color.parseColor("#00B395"));
        agreementBuilder.setSpan(agreementSpan, 7, 13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv_agreement.setText(agreementBuilder);
        SpannableStringBuilder agreementsecretBuilder = new SpannableStringBuilder(getResources().getText(R.string.tv_agreement_secret));
        ForegroundColorSpan agreementsecretSpan = new ForegroundColorSpan(Color.parseColor("#00B395"));
        agreementsecretBuilder.setSpan(agreementsecretSpan, 0, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv_agreement_secret.setText(agreementsecretBuilder);
        SpannableStringBuilder agreementchildBuilder = new SpannableStringBuilder(getResources().getText(R.string.tv_agreement_child));
        ForegroundColorSpan agreementchildSpan = new ForegroundColorSpan(Color.parseColor("#00B395"));
        agreementchildBuilder.setSpan(agreementchildSpan, 0, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv_agreement_child.setText(agreementchildBuilder);

        packageName = getPackageName();
    }


    int loginFrom = 0;
    private CWDialog cWDialog;

    /**
     * 发现您的手机被root，请谨慎操作！提示
     *
     * @param context
     */
    private void showConfirmDialog(Context context) {
        if (context != null) {
            String msgTips = getString(R.string.dialog_root_tips);
            if (cWDialog != null && cWDialog.isShowing()) {
                cWDialog.dismiss();
            }
            cWDialog = new CWDialog(context);
            cWDialog.setMessagWidePadding(msgTips).setPositiveButton("关闭", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    cWDialog.dismiss();
                }
            }).show();

            cWDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    cWDialog.dismiss();
                }
            });
        }
    }

    @Override
    protected void loadData() {
        String service_num = getString(R.string.service_phone);
        tv_service_num.setText("咨询客服( " + service_num + ")");
//        setCaptchaCode(iv_captcha_code); //（需要验证码的时候在打开）
        Intent intent = getIntent();
        if (intent != null) {
            String mobile = intent.getStringExtra(IntentFlag.INTENT_FLAG_STR);
            String psw = intent.getStringExtra(IntentFlag.INTENT_FLAG_PSW);

            loginFrom = intent.getIntExtra(IntentFlag.INTENT_FLAG_TYPE, 0);
            if (loginFrom == EConstants.LoginFrom.LOGIN_FROM_REGIST || loginFrom == EConstants.LoginFrom.LOGIN_FROM_RESETPSW) {
                //来自登陆注册页面初始化
                if (!TextUtils.isEmpty(mobile) && !TextUtils.isEmpty(psw)) {
                    switch (loginFrom) {
                        case EConstants.LoginFrom.LOGIN_FROM_REGIST://来自注册
                            loginAccount.setText(mobile);
                            edt_loginPassword.setText(psw);
                            EConstants.IS_YOUKE = false;
                            login();
                            break;
                        case EConstants.LoginFrom.LOGIN_FROM_RESETPSW://来自重置密码
                            loginAccount.setText(mobile);
                            edt_loginPassword.setText(psw);
                            break;
                    }
                }
            } else {
                SerializableManager.getInstance().deSerialize(
                        SerializableManager.SerializeKey.SHARE_KEY_USER_ACCOUNT_LIST, new BaseCallBack() {
                            @Override
                            public void success(Object data) {
                                try {
                                    //防止遗漏缓存导致类型转换错误
                                    List<UserAccountInfo> userAccountInfoList;
                                    userAccountInfoList = (ArrayList<UserAccountInfo>) data;

                                    if (null != userAccountInfoList && userAccountInfoList.size() > 0) {

                                        initMorePop(userAccountInfoList);
                                        initAccount(userAccountInfoList.get(0));

                                    } else {

                                        loginAccountPop = null;
                                        initAccount(null);

                                    }


                                } catch (ClassCastException e) {
                                    e.getStackTrace();
                                }


                            }

                            @Override
                            public void failed(int errorCode, Object data) {
                            }

                            @Override
                            public void failed(Object data) {
                            }
                        }, false);
            }
        }

        if ("com.ciwong.demoenglish".equals(getPackageName())) {
//            autoLogin();
        }
    }

    private void initAccount(UserAccountInfo userAccountInfo) {
        if (null != userAccountInfo) {
            if (userAccountInfo.getPhonelogin()) {

                loginAccount.setText(userAccountInfo.getPhoneNumber());
            } else {
                loginAccount.setText(String.valueOf(userAccountInfo.getUserId()));

            }
            if (null != userAccountInfo.getSchoolName() && !"".equals(userAccountInfo.getSchoolName())) {
                schoolId = userAccountInfo.getSchoolId();
                schoolName = userAccountInfo.getSchoolName();
                choose_school_edit.setText(userAccountInfo.getSchoolName());
                edt_password.setText(AESCBCUtil.decrypt(userAccountInfo.getUserPwd(), AESCBCUtil.AESCBC_HEX));
            }

            isQuickLogin = userAccountInfo.getQuickLogin();
            if (isQuickLogin) {
                setQuickLoginOrRealNameLogin(true);
            } else {
                setQuickLoginOrRealNameLogin(false);
            }

            if (null != userAccountInfo.getRealUserName() && !"".equals(userAccountInfo.getRealUserName())) {
                edt_chinese_nam.setText(userAccountInfo.getRealUserName());
            }

            edt_loginPassword.setText(AESCBCUtil.decrypt(userAccountInfo.getUserPwd(), AESCBCUtil.AESCBC_HEX));

        }
    }

    /**
     * 初始化账号登录Pop
     *
     * @param loginAccountInfos 已登录过用户集合
     */
    private void initMorePop(List<UserAccountInfo> loginAccountInfos) {
        if (loginAccountPop == null) {
            ListView listView = (ListView) View.inflate(this,
                    R.layout.login_account_pop, null);
            mAccountAdapter = new LoginAccountAdapter(this, loginAccountInfos);
            mAccountAdapter.setPopListItemListener(new PopListItemListener() {
                @Override
                public void deleteAccount(List<UserAccountInfo> userAccountInfoList, int position) {
                    loginAccountPop.dismiss();
                    if (userAccountInfoList == null) {
                        return;
                    }
                    userAccountInfoList.remove(position);
                    SerializableManager.getInstance().serialize(
                            SerializableManager.SerializeKey.SHARE_KEY_USER_ACCOUNT_LIST, (Serializable) userAccountInfoList, false);

                }
            });
            listView.setAdapter(mAccountAdapter);
            listView.setOnItemClickListener(
                    new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent,
                                                View view, int position, long id) {
                            UserAccountInfo userAccountInfo = (UserAccountInfo) parent.getItemAtPosition(position);
                            if (null != userAccountInfo) {
                                if (userAccountInfo.getPhonelogin()) {
                                    loginAccount.setText(userAccountInfo.getPhoneNumber());
                                } else {
                                    loginAccount.setText(String.valueOf(userAccountInfo.getUserId()));
                                }
                            }

                            loginAccountPop.dismiss();
//                            edt_loginPassword.requestFocus();
                            edt_loginPassword.setText(AESCBCUtil.decrypt(userAccountInfo.getUserPwd(), AESCBCUtil.AESCBC_HEX));

                        }
                    });
            loginAccountPop = new PopupWindow(listView);
            loginAccountPop.setBackgroundDrawable(new BitmapDrawable());
            loginAccountPop.setOutsideTouchable(true);
            loginAccountPop.setFocusable(true);
            loginAccountPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    loginMore.setImageResource(R.mipmap.login_more);
                }
            });
        } else {
            mAccountAdapter.clear();
            mAccountAdapter.addAll(loginAccountInfos);
        }
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
    }

    private int lastRootInvisibleHeight;

    /**
     * 控制软键盘布局
     *
     * @param root         最外层布局，需要调整的布局
     * @param scrollToView 被键盘遮挡的scrollToView，滚动root,使scrollToView在root可视区域的底部
     */
    private void controlKeyboardLayout(final View root, final View scrollToView) {
        root.getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        Rect rect = new Rect();
                        // 获取root在窗体的可视区域
                        root.getWindowVisibleDisplayFrame(rect);
                        // 获取root在窗体的不可视区域高度(被其他View遮挡的区域高度)
                        final int rootInvisibleHeight = root.getHeight()
                                - rect.bottom;
                        if (lastRootInvisibleHeight != 0 && lastRootInvisibleHeight == rootInvisibleHeight) {
                            return;
                        }
                        lastRootInvisibleHeight = rootInvisibleHeight;
                        // 若不可视区域高度大于100，则键盘显示
                        if (rootInvisibleHeight > 100) {
                            int[] location = new int[2];
                            // 获取scrollToView在窗体的坐标
                            scrollToView.getLocationInWindow(location);
                            // 计算root滚动高度，使scrollToView在可见区域
                            int srollHeight = (location[1]
                                    + scrollToView.getHeight()) - rect.bottom;
                            root.scrollTo(0, srollHeight);
                            AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
                            alphaAnimation.setDuration(500);
                            alphaAnimation.setFillAfter(true);
                            mIvLogo.startAnimation(alphaAnimation);

                        } else {
                            // 键盘隐藏
                            root.scrollTo(0, 0);
                            if (rootInvisibleHeight == 0 || rootInvisibleHeight == -getStatusBarHeight()) {
                                AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
                                alphaAnimation.setDuration(300);
                                alphaAnimation.setFillAfter(true);
                                mIvLogo.startAnimation(alphaAnimation);
                            }
                        }
                    }
                });
    }


    @Override
    public boolean isValidUserName(String userName) {
        Pattern pattern = Pattern.compile(
                "^[A-Za-z]{3,20}$|^[\u4e00-\u9fa5]{2,5}$|^[1-9][0-9]{4,15}$");
        boolean rs = pattern.matcher(userName.trim()).find();
        return rs;
    }

    @Override
    public boolean setUerNameError(String error) {
        if (!TextUtils.isEmpty(error)) {
            showToastError(error);
            loginAccount.requestFocus();
        }
        return true;
    }

    @Override
    public boolean setPasswordError(String error) {
        if (!TextUtils.isEmpty(error)) {
            showToastError(error);
            edt_loginPassword.requestFocus();
        }
        return true;
    }

    @Override
    public boolean setSchoolNameError(String error) {
        if (!TextUtils.isEmpty(error)) {
            showToastError(error);
            loginAccount.requestFocus();
        }
        return true;
    }

    @Override
    public void showLoginProgress(boolean show) {
        try {
            if (show) {
                ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(NewLoginActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                showCricleProgress(null);
            } else {
                hideCricleProgress();
            }
        } catch (Exception e) {
            e.getStackTrace();
        }


    }

    @Override
    public void showLoginErrorMsg(String msg) {
        hideCricleProgress();
        showToastError(msg);
        if (isQuickLogin) {
            //刷新验证码（需要验证码的时候在打开）
//            setCaptchaCode(iv_captcha_code);
        } else {
            //刷新验证码（需要验证码的时候在打开）
//            setCaptchaCode(iv_name_captcha_code);
        }
    }

    @Override
    public void navigateToHome(boolean isBindPhone, String passWord) {

        //获取本地手机号  若手机号为空 则请求网络
        if (!isBindPhone) {
            MeJumpManager.jumpToBindPhoneActivity(R.string.go_back, NewLoginActivity.this, "", "2");
            //2 标识  来自于绑定手机号验证
            this.finish();
        } else if (loginFrom == EConstants.LoginFrom.LOGIN_FROM_SUBMIT_WORK) {
            //直接结束
            setResult(RESULT_OK);
            this.finish();
        } else {
            Intent inTeIntent = new Intent(LoginToken.ACTION_LOGIN_SUCCESS);
            inTeIntent.putExtra(LoginToken.IS_BIND_PHONE, isBindPhone);
            sendBroadcast(inTeIntent);
            if (!MeUtil.validatePassword(passWord)) {
                showPasswordDialog();
            } else {
                EJumpManager.jumpToMain(0, NewLoginActivity.this);
                this.finish();
            }
        }
    }

    /**
     * 帐号改变
     *
     * @param s EditText
     */
    private void accountChange(Editable s) {
        if (s.length() > 0 && loginAccount.hasFocus()) {
            edt_loginPassword.setText("");
        } else {
            edt_loginPassword.setText("");
        }
    }

    /**
     * 显示账号Pop
     */
    private void showAccountPop() {
        if (!ImageLoaderHelper.getInstance().isInited()) {
            ImageLoaderHelper.getInstance().init(getApplicationContext());
        }
        if (loginAccountPop == null) {
            return;
        }
        loginAccountPop.showAsDropDown(mBelowLoginLL);
        int count = mAccountAdapter.getCount();
        if (count > 4) {
            count = 4;
        }
        loginAccountPop.update(ll_login_input.getWidth(),
                (int) (ll_login_input.getHeight() * count * (5.0 / 6)));

        loginMore.setImageResource(R.mipmap.login_more_up);
    }

    private void login() {
        try {
            String account;
            String realUserName = "";
            String password;
            String captchaCode;
            if (EConstants.IS_YOUKE) {
                account = "10000";
                password = "123456";
                captchaCode = "";

            } else if (isQuickLogin) {
                account = loginAccount.getText().toString().trim();
                password = edt_loginPassword.getText().toString();
                captchaCode = edt_login_captcha_code.getText().toString();

            } else {
                account = edt_chinese_nam.getText().toString().trim();
                realUserName = edt_chinese_nam.getText().toString().trim();
                captchaCode = edt_login_name_captcha_code.getText().toString();
                try {
                    account = java.net.URLEncoder.encode(account, "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    account = "";
                }
                password = edt_password.getText().toString();
            }
            if (isQuickLogin) {
                if (ll_select_brand.getVisibility() == View.VISIBLE && "100151".equals(EConstants.CLIENT_ID)) {
                    mLoginPresenter.validateCredentials(account, password, uuid, captchaCode);
                } else {
                    mLoginPresenter.validateCredentials(account, password, uuid, captchaCode);
                }
            } else {
                mLoginPresenter.validateRealName(account, realUserName, schoolId, schoolName, password, uuid, captchaCode);
            }
        } catch (Exception e) {
            e.getStackTrace();
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode != REQUEST_CODE_REGISTER_ACCOUNT) {
//            mController.onActivityResultData(requestCode, resultCode, data);
        }
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case REQUEST_CODE_REGISTER_ACCOUNT:// 注册成功回调
                    if (data != null) {
                        RegistUser user = (RegistUser) data
                                .getSerializableExtra(
                                        BaseIntentFlag.INTENT_FLAG_OBJ);
                        loginAccount.setText(String.valueOf(user.getUserId()));
                        edt_loginPassword.setText(data.getStringExtra(
                                BaseIntentFlag.INTENT_FLAG_STR));
                        CWDialog dialog = new CWDialog(this, false, false);
                        dialog.setTitle("注册成功");
                        dialog.setMessage(getString(R.string.congratulations,
                                user.getUserId() + ""));
                        dialog.setPositiveButton(getString(R.string.login),
                                new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog,
                                                        int which) {
                                        EConstants.IS_YOUKE = false;
                                        login();
                                    }
                                }, true, getResources().getDrawable(
                                        R.drawable.dialog_floor_selector));
                        dialog.show();
                    }
                    break;

                case RequestCode.MainActivityResquestCode.REQUEST_CODE_TO_CHOOSE_SCHOOL:
                    if (null != data) {
                        schoolId = data.getLongExtra(IntentFlag.INTENT_FLAG_SCHOOL_ID, 0);
                        schoolName = data.getStringExtra(IntentFlag.INTENT_FLAG_SCHOOL_NAME);
                        choose_school_edit.setText(schoolName);
                        if (TextUtils.isEmpty(edt_password.getText().toString()) || TextUtils.isEmpty(edt_chinese_nam.getText().toString()) ||
                                TextUtils.isEmpty(schoolName)) {
                            loginLogin.setEnabled(false);
                        } else {
                            loginLogin.setEnabled(true);
                        }
                    }

                default:
                    break;
            }
        }
    }


    /*-------------------------免密码登录处理----------------------------*/
    private LinearLayout ll_select_brand;
    private TextView et_select_brand;
    private ImageView iv_select_other_brand;
    private LinearLayout ll_logo_password;

    private PopupWindow brandAccountPop;
    private BrandAccountAdapter mBrandAdapter;
    public static final String KEY_NO_PWD_TO_LOGIN_BRAND_NAME = "KEY_NO_PWD_TO_LOGIN_BRAND_NAME";
    public static final String KEY_NO_PWD_TO_LOGIN_CURRENT_BRAND_ID = "KEY_NO_PWD_TO_LOGIN_BRAND_ID";
    public static final String KEY_NO_PWD_TO_LOGIN_CURRENT_BRAND_NAME = "KEY_NO_PWD_TO_LOGIN_CURRENT_BRAND_NAME";

    private void initNoPwdLogintPop(List<BrandBean> brandBeanList) {
        SerializableManager.getInstance().deSerialize(KEY_NO_PWD_TO_LOGIN_BRAND_NAME, new BaseCallBack() {
            @Override
            public void success(Object data) {
                try {
                    BrandBean brandBean = (BrandBean) data;
                    et_select_brand.setText(brandBean.getBrandName());
                    EApplication.BRAND_ID = brandBean.getBrandId();
                } catch (Exception e) {
                }
            }

            @Override
            public void failed(int errorCode, Object data) {
                if (getBrandList().size() > 0) {
                    BrandBean brandBean = getBrandList().get(0);
                    et_select_brand.setText(brandBean.getBrandName());
                    EApplication.BRAND_ID = brandBean.getBrandId();
                    SerializableManager.getInstance().serialize(KEY_NO_PWD_TO_LOGIN_BRAND_NAME, brandBean);
                }
            }

            @Override
            public void failed(Object data) {
                if (getBrandList().size() > 0) {
                    BrandBean brandBean = getBrandList().get(0);
                    et_select_brand.setText(brandBean.getBrandName());
                    EApplication.BRAND_ID = brandBean.getBrandId();
                    SerializableManager.getInstance().serialize(KEY_NO_PWD_TO_LOGIN_BRAND_NAME, brandBean);
                }
            }
        });
        if (brandAccountPop == null) {
            ListView listView = (ListView) View.inflate(this,
                    R.layout.brand_account_pop, null);
            mBrandAdapter = new BrandAccountAdapter(this, brandBeanList);
            listView.setAdapter(mBrandAdapter);
            listView.setOnItemClickListener(
                    new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent,
                                                View view, int position, long id) {

                            BrandBean brandBean = (BrandBean) parent.getItemAtPosition(position);
                            if (null != brandBean) {
                                EApplication.BRAND_ID = brandBean.getBrandId();
                                et_select_brand.setText(brandBean.getBrandName());
                            }
                            CWSys.setSharedInt(KEY_NO_PWD_TO_LOGIN_CURRENT_BRAND_ID, EApplication.BRAND_ID);
                            CWSys.setSharedString(KEY_NO_PWD_TO_LOGIN_CURRENT_BRAND_NAME, brandBean.getBrandName());
                            SerializableManager.getInstance().serialize(KEY_NO_PWD_TO_LOGIN_BRAND_NAME, brandBean);
                            brandAccountPop.dismiss();
                        }
                    });
            brandAccountPop = new PopupWindow(listView);
            brandAccountPop.setBackgroundDrawable(new BitmapDrawable());
            brandAccountPop.setOutsideTouchable(true);
            brandAccountPop.setFocusable(true);
            brandAccountPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    iv_select_other_brand.setImageResource(R.mipmap.login_more);
                }
            });
        } else {
            mBrandAdapter.clear();
            mBrandAdapter.addAll(brandBeanList);
        }
    }

    private List<BrandBean> getBrandList() {
        ArrayList<BrandBean> brandBeanList = new ArrayList<>();
        brandBeanList.add(new BrandBean("演示版", 524726977, R.drawable.yanshiban_ic_launcher));
        brandBeanList.add(new BrandBean("习习向上", 570678343, R.drawable.xixixiangshang_ic_launcher));
        brandBeanList.add(new BrandBean("爱习题", 539177610, R.drawable.aixiti_ic_launcher));
        brandBeanList.add(new BrandBean("5i英语", 380448713, R.drawable.fivei_ic_launcher));
        brandBeanList.add(new BrandBean("在线学", 544718987, R.drawable.zaixianxue_ic_launcher));
        brandBeanList.add(new BrandBean("掌上学英语", 485517281, R.drawable.zhangshang_ic_launcher));
        brandBeanList.add(new BrandBean("智学口语", 548877448, R.drawable.zhixue_ic_launcher));
        brandBeanList.add(new BrandBean("尚普教育", 386058686, R.drawable.shangpu_ic_launcher));
        brandBeanList.add(new BrandBean("智酷教育", 527177786, R.drawable.zhiku_ic_launcher));
        brandBeanList.add(new BrandBean("智慧周报", 549591709, R.drawable.zhihui_ic_launcher));
        brandBeanList.add(new BrandBean("A+学习社区", 535683172, R.drawable.aplus_launcher));
        brandBeanList.add(new BrandBean("学而优", 550341543, R.drawable.xueer_you_ic_launcher));
        brandBeanList.add(new BrandBean("金榜", 555868742, R.drawable.jinbang_ic_launcher));
        brandBeanList.add(new BrandBean("听说派", 549424407, R.drawable.tingshuopai_ic_launcher));


       /* brandBeanList.add(new BrandBean("稳派", 3213));
       brandBeanList.add(new BrandBean("教育周报", 543962675));
        brandBeanList.add(new BrandBean("东山外语", 401179));
        brandBeanList.add(new BrandBean("丹妮英语", 635224));

        brandBeanList.add(new BrandBean("学生英语", 487499123));
        brandBeanList.add(new BrandBean("习习宝", 524058207));
        brandBeanList.add(new BrandBean("萌迪教育", 529531950));
        brandBeanList.add(new BrandBean("习网学校", 543878981));
        brandBeanList.add(new BrandBean("点石教育", 548270855));
        brandBeanList.add(new BrandBean("久为教育", 548628562));
        brandBeanList.add(new BrandBean("名师大课堂", 548876268));
        brandBeanList.add(new BrandBean("亚太教育", 548885680));
        brandBeanList.add(new BrandBean("教辅通", 548940871));
        brandBeanList.add(new BrandBean("云听说", 549526526));
        brandBeanList.add(new BrandBean("智博口语", 549562583));
        brandBeanList.add(new BrandBean("酷爱学", 549609450));
        brandBeanList.add(new BrandBean("优+课堂", 551273274));
        brandBeanList.add(new BrandBean("e学趣练", 556353970));
        brandBeanList.add(new BrandBean("1+1英语", 557193944));
        brandBeanList.add(new BrandBean("e教时代", 557596214));
        brandBeanList.add(new BrandBean("高考核按钮", 561960175));
        brandBeanList.add(new BrandBean("丽学派", 579652491));
        brandBeanList.add(new BrandBean("全媒体电子报", 1));*/
        return brandBeanList;
    }

    /**
     * 显示账号Pop
     */
    private void showBrandAccountPop() {
        Log.e("showBrandAccountPop", "showBrandAccountPop: ");
        if (brandAccountPop == null) {
            return;
        }
        brandAccountPop.showAsDropDown(ll_select_brand);

        brandAccountPop.update(ll_select_brand.getWidth(),
                et_select_brand.getHeight() * 4);


    }

    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }

    private CWDialog cWPwdDialog;

    /**
     * 密码简单提示
     */
    private void showPasswordDialog() {
        String msgTips = getString(R.string.dialog_pass_tips);
        if (cWPwdDialog != null && cWPwdDialog.isShowing()) {
            cWPwdDialog.dismiss();
        }
        cWPwdDialog = new CWDialog(this);
        cWPwdDialog.setMessagWidePadding(msgTips).setPositiveButton("修改密码", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                MeJumpManager.jumpToModifyPassword(R.string.go_back,
                        NewLoginActivity.this);
                cWPwdDialog.dismiss();
            }
        }).setNegativeButtonTextColor(com.ciwong.mobilelib.R.color.color_light_green).show();

        cWPwdDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                cWPwdDialog.dismiss();
            }
        });
    }

    /**
     * 设置图形验证码
     */
    private void setCaptchaCode(ImageView iv_captcha_code) {
        uuid = UUID.randomUUID().toString();
        String code_url = "https://eapi.ciwong.com/gateway/v5/service/get_captcha_code_png?uuid=" + uuid;
        try {
            if (!ImageLoader.getInstance().isInited()) {
                ImageLoaderHelper.getInstance().init(getApplicationContext());
            }
            ImageLoader.getInstance().displayImage(code_url, iv_captcha_code,
                    EConstants.getEmptyUriOption(), new ImageLoadingListener() {
                        @Override
                        public void onLoadingStarted(String s, View view) {

                        }

                        @Override
                        public void onLoadingFailed(String s, View view, FailReason failReason) {
                            showToastAlert("加载验证码失败，请检查网络后重试！");
                        }

                        @Override
                        public void onLoadingComplete(String s, View view, Bitmap bitmap) {

                        }

                        @Override
                        public void onLoadingCancelled(String s, View view) {
//                            showToastAlert("加载验证码失败，请检查网络后重试！");
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
